package com.briup.jd2407cms.web.controller;

import com.briup.jd2407cms.domain.Slideshow;
import com.briup.jd2407cms.result.Result;
import com.briup.jd2407cms.service.impl.SlideshowServiceImpl;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/slideshow")
public class SlideshowController {
    @Autowired
    SlideshowServiceImpl slideshowService;

    @ApiOperation("通过id查询")
    @GetMapping("/queryById/{id}")
    public Result<Slideshow> findById(@PathVariable Integer id){
        Slideshow byId = slideshowService.getById(id);
        return Result.success(byId);
    }
    @ApiOperation("更新插入")
    @PostMapping("/saveOrUpdate")
    public Result<String> saveOrUpdate(@RequestBody Slideshow slideshow){
        slideshowService.saveOrUpdate(slideshow);
        return Result.success();
    }
    @ApiOperation("通过id删除")
    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable Integer id){
        slideshowService.removeById(id);
        return Result.success();
    }
    @ApiOperation("批量删除")
    @DeleteMapping("/deleteByBatch")
    public Result deleteByBatch(@RequestBody List<Integer> ids){
        slideshowService.removeByIds(ids);
        return Result.success();
    }
    @ApiOperation("查询所有可用")
    @GetMapping("/queryAllEnable")
    public Result<List<Slideshow>> queryAllEnable(){
        Map<String,Object> map=new HashMap<>();
        map.put("status","启用");
        List<Slideshow> slideshows = slideshowService.listByMap(map);
        return Result.success(slideshows);
    }
    @ApiOperation("分页查询")
    @GetMapping("/query")
    public Result<List<Slideshow>> query(@RequestParam Integer pageNum,@RequestParam Integer pageSize,
                        String status,String desc){
        return Result.success(slideshowService.getAllByPage(pageNum, pageSize, status, desc));
    }

}
